/**
 * in order to transfer non-primitive information, like socket, class, etc.
 * we need a global class to store these information, that is a child of
 * Application as we are implementing here, you can always access global information
 * stored in ConnectedApp as below:
 * ConnectedApp connected_app0  =  (ConnectedApp)getApplication();
 * one thing to remember, register ConnectedApp in the manifest file
 */

package com.tjian.fafa.user.base;

import android.app.Activity;

import com.tjian.fafa.user.base.bean.UserInfo;
import com.tjian.fafa.user.base.chatter.ChatActivity;
import com.tjian.fafa.user.base.mainBody.FrdRequestNotifActivity;

import java.util.ArrayList;
import java.util.List;

public class ConnectedApp
{

    private static ConnectedApp connectedApp_instance;

    private UserInfo userInfo;
    private Activity activity;
    private List<Activity> allActivities;

    private ChatActivity chatActivity;
    private FrdRequestNotifActivity frdRequestNotifActivity;

    public static ConnectedApp getInstance()
    {
        if (connectedApp_instance == null)
        {
            connectedApp_instance = new ConnectedApp();
        }
        return connectedApp_instance;
    }

    private ConnectedApp()
    {

    }

    public UserInfo getUserInfo()
    {
        return this.userInfo;
    }

    public void setUserInfo(UserInfo userInfo)
    {
        this.userInfo = userInfo;
    }

    public Activity getCurActivity()
    {
        return this.activity;
    }

    public void setCurActivity(Activity act0)
    {
        this.activity = act0;
    }

    public void instantiateListActivity()
    {
        this.allActivities = new ArrayList<Activity>();
    }

    public void clearListActivity()
    {
        if (this.allActivities != null)
        {
            for (Activity act : this.allActivities)
            {
                act.finish();
            }

            this.allActivities.clear();
        }
    }

    public void addItemIntoListActivity(Activity act0)
    {
        if (act0 == null)
        {
            return;
        }
        this.allActivities.add(act0);
    }

    public ChatActivity getChatActivity()
    {
        return chatActivity;
    }

    public void setChatActivity(ChatActivity ca0)
    {
        chatActivity = ca0;
    }

    public FrdRequestNotifActivity getFrdRequestNotifActivity()
    {
        return frdRequestNotifActivity;
    }

    public void setFrdRequestNotifActivity(FrdRequestNotifActivity ll)
    {
        frdRequestNotifActivity = ll;
    }

    public void clearAll()
    {
        clearListActivity();
        this.userInfo = null;
        this.activity = null;
        this.allActivities = null;
        this.connectedApp_instance = null;
    }
}
